package org.frend.rpc.impl;

import com.alibaba.dubbo.config.annotation.Service;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.frend.rpc.model.ProcessDefinitionModel;
import org.frend.rpc.service.ProcessDefinitionService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(timeout = 1200000)
public class ProcessDefinitionServiceImpl implements ProcessDefinitionService {

    @Autowired
    private RepositoryService repositoryService;

    @Override
    public List<ProcessDefinitionModel> queryCreateProcessDefinition() {
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
        List<ProcessDefinitionModel> listModel = new ArrayList<ProcessDefinitionModel>();
        for (ProcessDefinition processDefinition:list) {
            ProcessDefinitionModel model= new ProcessDefinitionModel();
            model.setCategory(processDefinition.getCategory());
            model.setDeploymentId(processDefinition.getDeploymentId());
            model.setDescription(processDefinition.getDescription());
            model.setDiagramResourceName(processDefinition.getDiagramResourceName());
            model.setHasStartFormKey(processDefinition.hasStartFormKey());
            model.setId(processDefinition.getId());
            model.setKey(processDefinition.getKey());
            model.setName(processDefinition.getName());
            model.setResourceName(processDefinition.getResourceName());
            model.setSuspended(processDefinition.isSuspended());
            model.setTenantId(processDefinition.getTenantId());
            model.setVersion(processDefinition.getVersion());
            listModel.add(model);
        }
        return listModel;
    }
}
